package cn.bellychang.leetcode.question100;

/**
 * @author ChangLiang
 * @date 2021/2/8
 */
public class Solution {

    public boolean isSameTree(TreeNode p, TreeNode q) {
        return isSame(p, q);
    }

    private boolean isSame(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null) {
            return false;
        } else if (q == null) {
            return false;
        }
        boolean left = isSame(p.left, q.left);
        if (left == false) {
            return false;
        }
        boolean middle = (p.val == q.val);
        if (middle == false) {
            return false;
        }
        boolean right = isSame(p.right, q.right);
        if (right == false) {
            return false;
        }
        return true;
    }
}
